package thread;

/**
 * 原子性问题
 * created by lanwp on 2019/2/26.
 */
public class AtomicDemo {

    private static int count = 0;

    private static void inc() {
        try {
            Thread.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        count++;
    }
    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 1000; i++) {
            new Thread(AtomicDemo::inc).start();// 运行结果：994  运行结果：1000
        }
        Thread.sleep(4000);
        System.out.println("运行结果：" + count);
    }
}
